SlideShare a Scribd company logo
1 of 15
Download to read offline
Boostライブラリ一周の旅
                       ver.1.44.0



                 高橋晶(Akira Takahashi)

   ブログ:「Faith and Brave – C++で遊ぼう」
    http://d.hatena.ne.jp/faith_and_brave/
                      Boost.勉強会#2 2010/09/11(Sat)
はじめに



前回は、Boost 1.40.0までを紹介しました。

今回は1.44.0までの差分を紹介します。
本日紹介するライブラリ


1. Property Tree
2. Uuid
3. Range 2.0
4. Filesystem v3
5. Polygon
6. Meta State Machine(MSM)
Property Tree 1/4
汎用的な、木構造をもつデータのプロパティ管理。
XML、JSON、INIファイルのパーサーを提供している。

全てのデータは、
boost::property_tree::ptree型
に対して操作を行う。

値の取得には、
失敗時に例外を投げるptee::get<T>()と
boost::optionalを返すptree::get_optional<T>()
が用意されている。
Property Tree 2/4
 XMLの読込、要素、属性の取得。
 XMLパーサーにはRapidXmlを採用している。
                                          <root>
                                           <elem attr="World">
                                             Hello
using namespace boost::property_tree;      </elem>
                                          </root>
ptree pt;
read_xml("test.xml", pt, xml_parser::trim_whitespace);

// 要素の取得
const string& elem = pt.get<string>("root.elem");

// 属性の取得 : <xmlattr>という特殊な要素名を介してアクセスする
const string& attr = pt.get<string>("root.elem.<xmlattr>.attr");
Property Tree 3/4
 JSONの読込、データの取得。                         {
                                             "Data": {
                                               "Value": 314,
                                               "Str": "Hello"
                                             }
using namespace boost::property_tree;    }

ptree pt;
read_json("test.json", pt);

const int     value = pt.get<int>("Data.Value");
const string& str = pt.get<string>("Data.Str");
Property Tree 4/4
 iniの読込、データの取得。                          [Data]
                                         Value = 314
                                         Str = Hello


using namespace boost::property_tree;

ptree pt;
read_ini("test.ini", pt);

const int     value = pt.get<int>("Data.Value");
const string& str = pt.get<string>("Data.Str");
Uuid
 ユニークIDの生成。
 COMとか、分散環境での情報の識別とかで
 使われることが多い。

using namespace boost::uuids;

// 擬似乱数生成器でのUUID生成。デフォルトはmt19937
uuid u1 = random_generator()();

// 文字列からUUID生成
uuid u2 = string_generator()("0123456789abcdef0123456789abcdef");

cout << u1 << endl;
cout << u2 << endl;

                      31951f08-5512-4942-99ce-ae2f19351b82
                      01234567-89ab-cdef-0123-456789abcdef
Range2.0 1/2
 ユーティリティ程度だったBoost.Rangeに、
 RangeアルゴリズムとRangeアダプタを拡張。

std::vector<int> v;

// Rangeアルゴリズム : イテレータの組ではなく範囲を渡す
boost::sort(v);
boost::for_each(v, f);

// Rangeアダプタ
using namespace boost::adaptors;
boost::for_each(v | filtered(p) | transformed(conv), f);


 Rangeアルゴリズム : STLアルゴリズムのRange版
 Rangeアダプタ   : 遅延評価され、合成可能な範囲操作
Range 2.0 2/2
 Boost.Foreachと組み合わせて使っても便利。
using namespace boost::adaptors;
std::map<std::string, int> m;

// mapのキーのみを操作
BOOST_FOREACH (const std::string& key, m | map_keys) {
  // something...
}

// mapの値のみを操作
BOOST_FOREACH (const int value, m | map_values) {
  // なにか・・・
}


  RangeライブラリとしてはOvenも強力なのでそちらもチェックしてください!
Filesystem v3
 pathの日本語対応等。
 stringとwstringの両方を使用するためにオーバーロードが
 必要なくなったり。

#define BOOST_FILESYSTEM_VERSION 3
#include <boost/filesystem.hpp>

void foo(const boost::filesystem::path& path) {}

int main()
{
    foo("english");
    foo(L"日本語"); // v2ではエラー
}
Polygon
    平面多角形(2D)のアルゴリズムを提供するライブラリ。
    以下は、三角形の内外判定。
#include <boost/polygon/polygon.hpp>
namespace polygon = boost::polygon;

int main()
{
    const std::vector<polygon::point_data<int>> ptrs = {
        {0, 0}, {10, 0}, {10, 10}
    };
    const polygon::polygon_data<int> poly(ptrs.begin(), ptrs.end());

     // 点が三角形の内側にあるか
     const polygon::point_data<int> p(3, 3);
     assert(polygon::contains(poly, p));
}
Meta State Machine(MSM) 1/2
 新たな状態マシンライブラリ。状態遷移表を直接記述する。
namespace msm = boost::msm;
struct Active : msm::front::state<> {};
struct Stopped : msm::front::state<> {};
struct StartStopEvent {};
struct ResetEvent {};

struct StopWatch_ : msm::front::state_machine_def<StopWatch_> {
    typedef Stopped initial_state;
    struct transition_table : boost::mpl::vector<
//           Start    Event           Next
        _row<Active, StartStopEvent, Stopped>,
        _row<Active, ResetEvent,      Stopped>,
        _row<Stopped, StartStopEvent, Active>
    > {};
};

typedef msm::back::state_machine<StopWatch_> StopWatch;
Meta State Machine(MSM) 2/2
    新たな状態マシンライブラリ。状態遷移表を直接記述する。



int main()
{
    StopWatch watch;

     watch.start();
     watch.process_event(StartStopEvent());   //   stop   ->   run
     watch.process_event(StartStopEvent());   //   run    ->   stop
     watch.process_event(StartStopEvent());   //   stop   ->   run
     watch.process_event(ResetEvent());       //   run    ->   stop
}
まとめ(?)


• 1.44.0になってライブラリがかなり充実しまし
  た。

• とくにRange 2.0はプログラミングスタイルを変
  えるほどのライブラリなのでオススメです。

More Related Content

What's hot

Commit ускоривший python 2.7.11 на 30% и новое в python 3.5
Commit ускоривший python 2.7.11 на 30% и новое в python 3.5Commit ускоривший python 2.7.11 на 30% и новое в python 3.5
Commit ускоривший python 2.7.11 на 30% и новое в python 3.5PyNSK
 
Use C++ to Manipulate mozSettings in Gecko
Use C++ to Manipulate mozSettings in GeckoUse C++ to Manipulate mozSettings in Gecko
Use C++ to Manipulate mozSettings in GeckoChih-Hsuan Kuo
 
groovy databases
groovy databasesgroovy databases
groovy databasesPaul King
 
Java 7 - short intro to NIO.2
Java 7 - short intro to NIO.2Java 7 - short intro to NIO.2
Java 7 - short intro to NIO.2Martijn Verburg
 
Spock Framework - Slidecast
Spock Framework - SlidecastSpock Framework - Slidecast
Spock Framework - SlidecastDaniel Kolman
 
Multithreaded programming
Multithreaded programmingMultithreaded programming
Multithreaded programmingSonam Sharma
 
The TCP/IP stack in the FreeBSD kernel COSCUP 2014
The TCP/IP stack in the FreeBSD kernel COSCUP 2014The TCP/IP stack in the FreeBSD kernel COSCUP 2014
The TCP/IP stack in the FreeBSD kernel COSCUP 2014Kevin Lo
 
Building modern web apps with html5, javascript, and java
Building modern web apps with html5, javascript, and javaBuilding modern web apps with html5, javascript, and java
Building modern web apps with html5, javascript, and javaAlexander Gyoshev
 
C++の話(本当にあった怖い話)
C++の話(本当にあった怖い話)C++の話(本当にあった怖い話)
C++の話(本当にあった怖い話)Yuki Tamura
 
concurrency with GPars
concurrency with GParsconcurrency with GPars
concurrency with GParsPaul King
 
Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36Chih-Hsuan Kuo
 
Python import mechanism
Python import mechanismPython import mechanism
Python import mechanismYuki Nishiwaki
 
[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization
[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization
[Pgday.Seoul 2021] 2. Porting Oracle UDF and OptimizationPgDay.Seoul
 
Protocol handler in Gecko
Protocol handler in GeckoProtocol handler in Gecko
Protocol handler in GeckoChih-Hsuan Kuo
 

What's hot (20)

Commit ускоривший python 2.7.11 на 30% и новое в python 3.5
Commit ускоривший python 2.7.11 на 30% и новое в python 3.5Commit ускоривший python 2.7.11 на 30% и новое в python 3.5
Commit ускоривший python 2.7.11 на 30% и новое в python 3.5
 
Use C++ to Manipulate mozSettings in Gecko
Use C++ to Manipulate mozSettings in GeckoUse C++ to Manipulate mozSettings in Gecko
Use C++ to Manipulate mozSettings in Gecko
 
groovy databases
groovy databasesgroovy databases
groovy databases
 
What is recursion?
What is recursion? What is recursion?
What is recursion?
 
Java 7 - short intro to NIO.2
Java 7 - short intro to NIO.2Java 7 - short intro to NIO.2
Java 7 - short intro to NIO.2
 
Spock Framework - Slidecast
Spock Framework - SlidecastSpock Framework - Slidecast
Spock Framework - Slidecast
 
Multithreaded programming
Multithreaded programmingMultithreaded programming
Multithreaded programming
 
The TCP/IP stack in the FreeBSD kernel COSCUP 2014
The TCP/IP stack in the FreeBSD kernel COSCUP 2014The TCP/IP stack in the FreeBSD kernel COSCUP 2014
The TCP/IP stack in the FreeBSD kernel COSCUP 2014
 
Building modern web apps with html5, javascript, and java
Building modern web apps with html5, javascript, and javaBuilding modern web apps with html5, javascript, and java
Building modern web apps with html5, javascript, and java
 
Programming in C
Programming in CProgramming in C
Programming in C
 
C++の話(本当にあった怖い話)
C++の話(本当にあった怖い話)C++の話(本当にあった怖い話)
C++の話(本当にあった怖い話)
 
concurrency with GPars
concurrency with GParsconcurrency with GPars
concurrency with GPars
 
Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36
 
Storm introduction
Storm introductionStorm introduction
Storm introduction
 
Python import mechanism
Python import mechanismPython import mechanism
Python import mechanism
 
[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization
[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization
[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization
 
Network security
Network securityNetwork security
Network security
 
Functions
FunctionsFunctions
Functions
 
R part iii
R part iiiR part iii
R part iii
 
Protocol handler in Gecko
Protocol handler in GeckoProtocol handler in Gecko
Protocol handler in Gecko
 

Similar to Boostライブラリ一周の旅

[232] TensorRT를 활용한 딥러닝 Inference 최적화
[232] TensorRT를 활용한 딥러닝 Inference 최적화[232] TensorRT를 활용한 딥러닝 Inference 최적화
[232] TensorRT를 활용한 딥러닝 Inference 최적화NAVER D2
 
[232]TensorRT를 활용한 딥러닝 Inference 최적화
[232]TensorRT를 활용한 딥러닝 Inference 최적화[232]TensorRT를 활용한 딥러닝 Inference 최적화
[232]TensorRT를 활용한 딥러닝 Inference 최적화NAVER D2
 
The TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelThe TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelDivye Kapoor
 
Unit 4
Unit 4Unit 4
Unit 4siddr
 
Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Yandex
 
ch 7 POSIX.pptx
ch 7 POSIX.pptxch 7 POSIX.pptx
ch 7 POSIX.pptxsibokac
 
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres OpenBruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres OpenPostgresOpen
 
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан КольцовRust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан КольцовYandex
 
Create a JAVA program that performs file IO and database interaction.pdf
Create a JAVA program that performs file IO and database interaction.pdfCreate a JAVA program that performs file IO and database interaction.pdf
Create a JAVA program that performs file IO and database interaction.pdfmalavshah9013
 
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2 「エッジAIモダン計測制御の世界」オ...
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2  「エッジAIモダン計測制御の世界」オ...Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2  「エッジAIモダン計測制御の世界」オ...
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2 「エッジAIモダン計測制御の世界」オ...Mr. Vengineer
 
Threads Advance in System Administration with Linux
Threads Advance in System Administration with LinuxThreads Advance in System Administration with Linux
Threads Advance in System Administration with LinuxSoumen Santra
 
Unit 3
Unit  3Unit  3
Unit 3siddr
 
Unit 6
Unit 6Unit 6
Unit 6siddr
 
Lab01Filesbuild.bat@echo offclsset DRIVE_LETTER=1.docx
Lab01Filesbuild.bat@echo offclsset DRIVE_LETTER=1.docxLab01Filesbuild.bat@echo offclsset DRIVE_LETTER=1.docx
Lab01Filesbuild.bat@echo offclsset DRIVE_LETTER=1.docxDIPESH30
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentalsHCMUTE
 

Similar to Boostライブラリ一周の旅 (20)

[232] TensorRT를 활용한 딥러닝 Inference 최적화
[232] TensorRT를 활용한 딥러닝 Inference 최적화[232] TensorRT를 활용한 딥러닝 Inference 최적화
[232] TensorRT를 활용한 딥러닝 Inference 최적화
 
[232]TensorRT를 활용한 딥러닝 Inference 최적화
[232]TensorRT를 활용한 딥러닝 Inference 최적화[232]TensorRT를 활용한 딥러닝 Inference 최적화
[232]TensorRT를 활용한 딥러닝 Inference 최적화
 
The TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelThe TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux Kernel
 
Unit 4
Unit 4Unit 4
Unit 4
 
Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++
 
ch 7 POSIX.pptx
ch 7 POSIX.pptxch 7 POSIX.pptx
ch 7 POSIX.pptx
 
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres OpenBruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
 
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан КольцовRust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
 
Posix Threads
Posix ThreadsPosix Threads
Posix Threads
 
Oop 1
Oop 1Oop 1
Oop 1
 
Create a JAVA program that performs file IO and database interaction.pdf
Create a JAVA program that performs file IO and database interaction.pdfCreate a JAVA program that performs file IO and database interaction.pdf
Create a JAVA program that performs file IO and database interaction.pdf
 
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2 「エッジAIモダン計測制御の世界」オ...
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2  「エッジAIモダン計測制御の世界」オ...Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2  「エッジAIモダン計測制御の世界」オ...
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2 「エッジAIモダン計測制御の世界」オ...
 
srgoc
srgocsrgoc
srgoc
 
Summary of C++17 features
Summary of C++17 featuresSummary of C++17 features
Summary of C++17 features
 
Threads Advance in System Administration with Linux
Threads Advance in System Administration with LinuxThreads Advance in System Administration with Linux
Threads Advance in System Administration with Linux
 
Unit 3
Unit  3Unit  3
Unit 3
 
C1320prespost
C1320prespostC1320prespost
C1320prespost
 
Unit 6
Unit 6Unit 6
Unit 6
 
Lab01Filesbuild.bat@echo offclsset DRIVE_LETTER=1.docx
Lab01Filesbuild.bat@echo offclsset DRIVE_LETTER=1.docxLab01Filesbuild.bat@echo offclsset DRIVE_LETTER=1.docx
Lab01Filesbuild.bat@echo offclsset DRIVE_LETTER=1.docx
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 

More from Akira Takahashi (20)

Cpp20 overview language features
Cpp20 overview language featuresCpp20 overview language features
Cpp20 overview language features
 
Cppmix 02
Cppmix 02Cppmix 02
Cppmix 02
 
Cppmix 01
Cppmix 01Cppmix 01
Cppmix 01
 
Modern C++ Learning
Modern C++ LearningModern C++ Learning
Modern C++ Learning
 
cpprefjp documentation
cpprefjp documentationcpprefjp documentation
cpprefjp documentation
 
C++1z draft
C++1z draftC++1z draft
C++1z draft
 
Boost tour 1_61_0 merge
Boost tour 1_61_0 mergeBoost tour 1_61_0 merge
Boost tour 1_61_0 merge
 
Boost tour 1_61_0
Boost tour 1_61_0Boost tour 1_61_0
Boost tour 1_61_0
 
error handling using expected
error handling using expectederror handling using expected
error handling using expected
 
Boost tour 1.60.0 merge
Boost tour 1.60.0 mergeBoost tour 1.60.0 merge
Boost tour 1.60.0 merge
 
Boost tour 1.60.0
Boost tour 1.60.0Boost tour 1.60.0
Boost tour 1.60.0
 
Boost container feature
Boost container featureBoost container feature
Boost container feature
 
Boost Tour 1_58_0 merge
Boost Tour 1_58_0 mergeBoost Tour 1_58_0 merge
Boost Tour 1_58_0 merge
 
Boost Tour 1_58_0
Boost Tour 1_58_0Boost Tour 1_58_0
Boost Tour 1_58_0
 
C++14 solve explicit_default_constructor
C++14 solve explicit_default_constructorC++14 solve explicit_default_constructor
C++14 solve explicit_default_constructor
 
C++14 enum hash
C++14 enum hashC++14 enum hash
C++14 enum hash
 
Multi paradigm design
Multi paradigm designMulti paradigm design
Multi paradigm design
 
Start Concurrent
Start ConcurrentStart Concurrent
Start Concurrent
 
Programmer mind
Programmer mindProgrammer mind
Programmer mind
 
Boost.Study 14 Opening
Boost.Study 14 OpeningBoost.Study 14 Opening
Boost.Study 14 Opening
 

Boostライブラリ一周の旅

  • 1. Boostライブラリ一周の旅 ver.1.44.0 高橋晶(Akira Takahashi) ブログ:「Faith and Brave – C++で遊ぼう」 http://d.hatena.ne.jp/faith_and_brave/ Boost.勉強会#2 2010/09/11(Sat)
  • 3. 本日紹介するライブラリ 1. Property Tree 2. Uuid 3. Range 2.0 4. Filesystem v3 5. Polygon 6. Meta State Machine(MSM)
  • 5. Property Tree 2/4 XMLの読込、要素、属性の取得。 XMLパーサーにはRapidXmlを採用している。 <root> <elem attr="World"> Hello using namespace boost::property_tree; </elem> </root> ptree pt; read_xml("test.xml", pt, xml_parser::trim_whitespace); // 要素の取得 const string& elem = pt.get<string>("root.elem"); // 属性の取得 : <xmlattr>という特殊な要素名を介してアクセスする const string& attr = pt.get<string>("root.elem.<xmlattr>.attr");
  • 6. Property Tree 3/4 JSONの読込、データの取得。 { "Data": { "Value": 314, "Str": "Hello" } using namespace boost::property_tree; } ptree pt; read_json("test.json", pt); const int value = pt.get<int>("Data.Value"); const string& str = pt.get<string>("Data.Str");
  • 7. Property Tree 4/4 iniの読込、データの取得。 [Data] Value = 314 Str = Hello using namespace boost::property_tree; ptree pt; read_ini("test.ini", pt); const int value = pt.get<int>("Data.Value"); const string& str = pt.get<string>("Data.Str");
  • 8. Uuid ユニークIDの生成。 COMとか、分散環境での情報の識別とかで 使われることが多い。 using namespace boost::uuids; // 擬似乱数生成器でのUUID生成。デフォルトはmt19937 uuid u1 = random_generator()(); // 文字列からUUID生成 uuid u2 = string_generator()("0123456789abcdef0123456789abcdef"); cout << u1 << endl; cout << u2 << endl; 31951f08-5512-4942-99ce-ae2f19351b82 01234567-89ab-cdef-0123-456789abcdef
  • 9. Range2.0 1/2 ユーティリティ程度だったBoost.Rangeに、 RangeアルゴリズムとRangeアダプタを拡張。 std::vector<int> v; // Rangeアルゴリズム : イテレータの組ではなく範囲を渡す boost::sort(v); boost::for_each(v, f); // Rangeアダプタ using namespace boost::adaptors; boost::for_each(v | filtered(p) | transformed(conv), f); Rangeアルゴリズム : STLアルゴリズムのRange版 Rangeアダプタ : 遅延評価され、合成可能な範囲操作
  • 10. Range 2.0 2/2 Boost.Foreachと組み合わせて使っても便利。 using namespace boost::adaptors; std::map<std::string, int> m; // mapのキーのみを操作 BOOST_FOREACH (const std::string& key, m | map_keys) { // something... } // mapの値のみを操作 BOOST_FOREACH (const int value, m | map_values) { // なにか・・・ } RangeライブラリとしてはOvenも強力なのでそちらもチェックしてください!
  • 11. Filesystem v3 pathの日本語対応等。 stringとwstringの両方を使用するためにオーバーロードが 必要なくなったり。 #define BOOST_FILESYSTEM_VERSION 3 #include <boost/filesystem.hpp> void foo(const boost::filesystem::path& path) {} int main() { foo("english"); foo(L"日本語"); // v2ではエラー }
  • 12. Polygon 平面多角形(2D)のアルゴリズムを提供するライブラリ。 以下は、三角形の内外判定。 #include <boost/polygon/polygon.hpp> namespace polygon = boost::polygon; int main() { const std::vector<polygon::point_data<int>> ptrs = { {0, 0}, {10, 0}, {10, 10} }; const polygon::polygon_data<int> poly(ptrs.begin(), ptrs.end()); // 点が三角形の内側にあるか const polygon::point_data<int> p(3, 3); assert(polygon::contains(poly, p)); }
  • 13. Meta State Machine(MSM) 1/2 新たな状態マシンライブラリ。状態遷移表を直接記述する。 namespace msm = boost::msm; struct Active : msm::front::state<> {}; struct Stopped : msm::front::state<> {}; struct StartStopEvent {}; struct ResetEvent {}; struct StopWatch_ : msm::front::state_machine_def<StopWatch_> { typedef Stopped initial_state; struct transition_table : boost::mpl::vector< // Start Event Next _row<Active, StartStopEvent, Stopped>, _row<Active, ResetEvent, Stopped>, _row<Stopped, StartStopEvent, Active> > {}; }; typedef msm::back::state_machine<StopWatch_> StopWatch;
  • 14. Meta State Machine(MSM) 2/2 新たな状態マシンライブラリ。状態遷移表を直接記述する。 int main() { StopWatch watch; watch.start(); watch.process_event(StartStopEvent()); // stop -> run watch.process_event(StartStopEvent()); // run -> stop watch.process_event(StartStopEvent()); // stop -> run watch.process_event(ResetEvent()); // run -> stop }
  • 15. まとめ(?) • 1.44.0になってライブラリがかなり充実しまし た。 • とくにRange 2.0はプログラミングスタイルを変 えるほどのライブラリなのでオススメです。